<?php
namespace app\common\service;
use \app\common\model\UserBank as UserBankModel;
use think\Loader;
use app\common\library\Sms as Smslib;
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/3/6
 * Time: 17:59
 */
class UserBank extends Base {
    public function __construct()
    {
        parent::__construct();
        $UserBankModel =  new UserBankModel();
        $this->model = $UserBankModel;
    }
    /**
     * 添加提现账号
     */
    public  function bindUserBank($map,$data){
        $validate =  Loader::validate('UserBank');
        if(!$validate->check($data)){
            $datas = json_encode((object)null);
            return ['code'=>3,'msg'=>$validate->getError(),'data'=>$datas];
        }
        $event = 'bankCode';
        $ret = Smslib::check($data['mobile'], $data['code'], $event);

        if($ret){
            $model = $this->model;
            $res = $model->where($map)->find();
            if($res){
                return ['code'=>2,'msg'=>'已经绑过卡了'];
            }
            $data['status']=0;
            $data['createtime']=time();
            unset($data["code"]);
            $_datas = $model->insertGetId($data);
            if($_datas){
                $data['id']=$_datas;
                return ['code'=>1,'msg'=>'绑卡成功'];
            }else{
                return ['code'=>0,'msg'=>'绑卡失败'];
            }
        }else{
            return ['code'=>0,'msg'=>'手机验证码不正确'];
        }

    }

    public  function getBrankInfo($id){

        $map['id']=$id;
        $list = $this->model->where($map)->find();
        return $list ;

    }
}